import re

class User:
    def __init__(self,
                 userID: str = None,
                 password: str = None,
                 type: str = None,
                 name: str = None,
                 email: str = None,
                 valid: bool = False):
        self.userID = userID
        self.password = password
        self.type = type
        self.name = name
        self.email = email
        self.valid = valid

    def to_string(self):
        return "userID: {}, password: {}, type: {}, name: {}, email: {}, valid: {} ".format(
            self.userID, self.password, self.type, self.name, self.email, self.valid)

    def userid_re(self):
        ret=0
        userID_pattern = re.compile(r'^\d{13}$')
        matchOBJ = re.match(userID_pattern, self.userID)
        if matchOBJ is None:
            ret = 4013
        elif self.userID == matchOBJ.group():
            ret = 1
        else:
            ret = 0
        return ret

    def password_re(self):
        ret = 0
        password_pattern = re.compile(r'^(?=.*[a-z])(?=.*\d)[A-Za-z\d]{6,20}$')
        matchOBJ =  re.match(password_pattern,self.password)
        if matchOBJ is None:
            ret = 4014
        elif self.password == matchOBJ.group():
            ret = 1
        else:
            ret = 0
        return ret

    def email_re(self):
        ret = 0
        email_pattern = re.compile(r'^([A-z0-9]{6,18})(\w|\-)+@[A-z0-9]+\.([A-z]{2,3})$')
        matchOBJ = re.match(email_pattern,self.email)
        if matchOBJ is None:
            ret = 4015
        elif self.email == matchOBJ.group():
            ret = 1
        else:
            ret = 0
        return ret


if __name__ == "__main__":
    email_pattern = re.compile(r'^([A-z0-9]{6,18})(\w|\-)+@[A-z0-9]+\.([A-z]{2,3})$')
    matchOBJ = re.match(email_pattern, "1596252493@qq.com")
    print(matchOBJ)